<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    // 拓展:快速排序

    var list = [24, 37, 61, 52, 79, 83, 17];


    function quickSort(list) {
        if(list.length  <= 1) return list;
        list = list.slice(); //对原数组进行深复制 (得到一个与原数组元素相同的新数组)
        var midIndex = Math.floor(list.length / 2);
        var mid = list.splice(midIndex, 1)[0]; // splice返回被删除的元素形成的数组
        console.log(mid);

        var left = [];
        var right = [];
        for (var item of list) {
            if (item > mid) {
                right.push(item);
            } else {
                left.push(item);
            }
        }
        console.log(left, mid, right);

        return quickSort(left).concat(mid,quickSort(right));


    }

    var result = quickSort(list);
    console.log(result);
    console.log(list);


    



</script>

</html>